package com.hzit.cart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzit.cart.api.domain.Address;
import com.hzit.cart.interceptor.LoginInterceptor;
import com.hzit.cart.mapper.AddressMapper;
import com.hzit.cart.service.IAddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzit.common.entity.LoginUser;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hbxfwf
 * @since 2023-09-25
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements IAddressService {

	//1. 得到登录用户的地址列表
	@Override
	public List<Address> findAll() {
		//1.1 从线程本地变量中获取登录用户
		LoginUser loginUser = LoginInterceptor.threadLocal.get();
		String userId = loginUser.getLogin();
		//1.2 通过userid查询出当前登录用户的地址列表
		return this.list(new QueryWrapper<Address>().eq("user_id",userId));
	}
}
